import { createSlice, PayloadAction } from '@reduxjs/toolkit';

interface Language {
  id: string;
  name: string;
}


interface LanguageState {
  languages: Language[];
  loading: boolean;
  error: string | null;
  languageCount: number;
}

const initialState: LanguageState = {
  languages: [],
  loading: false,
  error: null,
  languageCount: 0,
};

const languageSlice = createSlice({
  name: 'language',
  initialState,
  reducers: {
    setLanguagesInfo: (state, action: PayloadAction<Language[]>) => {
      state.languages = action.payload;
    },
    setLoading: (state, action: PayloadAction<boolean>) => {
      state.loading = action.payload;
    },
    setLanguageCount: (state, action: PayloadAction<number>) => {
      state.languageCount = action.payload;
    },
    setError: (state, action: PayloadAction<string | null>) => {
      state.error = action.payload;
    },
  },
});

export const { setLanguagesInfo, setLoading, setError,setLanguageCount  } = languageSlice.actions;
export default languageSlice.reducer;